home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / folder watching / fw receiver / events.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.5 KB  |  187 lines

  1. /*
  2.     File:        Events.c
  3.  
  4.     Contains:    Main event loop and basic keyboard/mouse processing
  5.  
  6.     Written by: Chris White    
  7.  
  8.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/21/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 26/01/96    GS                FW Receiver
  21.                                             Added call to remove Notification when suspend or
  22.                                             resume event received.
  23.                 
  24.  
  25. */
  26.  
  27. #pragma segment Core
  28.  
  29.  
  30. // System Includes
  31.  
  32. #ifndef __MEMORY__
  33.     #include <Memory.h>
  34. #endif
  35.  
  36. #ifndef __APPLEEVENTS__
  37.     #include <AppleEvents.h>
  38. #endif
  39.  
  40. #ifndef __DIALOGS__
  41.     #include <Dialogs.h>
  42. #endif
  43.  
  44. #ifndef __DESK__
  45.     #include <Desk.h>
  46. #endif
  47.  
  48. #ifndef __WINDOWS__
  49.     #include <Windows.h>
  50. #endif
  51.  
  52.  
  53.  
  54.  
  55. // Application includes
  56.  
  57. #ifndef __BAREBONES__
  58.     #include "BareBones.h"
  59. #endif
  60.  
  61. #ifndef __PROTOTYPES__
  62.     #include "Prototypes.h"
  63. #endif
  64.  
  65.  
  66.  
  67.  
  68. // static includes
  69.  
  70. static void DoMouseDown ( EventRecord* theEvent );
  71. static void DoKey ( EventRecord*theEvent );
  72.  
  73.  
  74.  
  75. void EventLoop ( void )
  76. {
  77.     OSErr            theErr;
  78.     EventRecord        theEvent;
  79.     
  80.     
  81.     while ( !gQuit )
  82.     {
  83.         WaitNextEvent ( everyEvent, &theEvent, gSleepTime, nil );    
  84.         
  85.         switch ( theEvent.what )
  86.         {
  87.             case mouseDown: 
  88.                 DoMouseDown ( &theEvent );
  89.             break;
  90.             
  91.             case keyDown:
  92.             case autoKey: 
  93.                 DoKey ( &theEvent );
  94.             break;
  95.             
  96.             case activateEvt: 
  97.                 DoActivate ( &theEvent );
  98.             break;
  99.             
  100.             case updateEvt:
  101.                 DoUpdate ( &theEvent );
  102.             break;
  103.             
  104.             case osEvt:
  105.                 if ( (theEvent.message >> 24) & suspendResumeMessage )    // suspend or resume
  106.                 {
  107.                     // Modify the event record to look like an activate/deactivate event
  108.                     theEvent.modifiers = theEvent.message;        // Copy suspend/resume flag
  109.                     theEvent.message = (long) FrontWindow ( );    
  110.  
  111.                     (void)RemoveNotification( );    // Removes notification if there is one
  112.  
  113.                     DoActivate ( &theEvent );
  114.                 }
  115.             break;
  116.             
  117.             case kHighLevelEvent:
  118.                 theErr = AEProcessAppleEvent ( &theEvent );
  119.             break;
  120.         }
  121.     }
  122.     
  123.     return;
  124.     
  125. } // EventLoop
  126.  
  127.  
  128.  
  129. static void DoMouseDown ( EventRecord* theEvent )
  130. {
  131.     Point            globalPt = theEvent->where;
  132.     SInt16            windowPart;
  133.     WindowRef        theWindow;
  134.     long            theMenu;
  135.     
  136.     
  137.     windowPart = FindWindow ( globalPt, &theWindow );
  138.     switch ( windowPart )
  139.     {
  140.         case inMenuBar: 
  141.             theMenu = MenuSelect ( globalPt );
  142.             MenuDispatch ( theMenu );
  143.         break;
  144.         
  145.         case inSysWindow:
  146.             // The SystemClick toolbox routine handles system events
  147.             SystemClick ( theEvent, theWindow );
  148.         break;
  149.         
  150.         case inGoAway:
  151.             // We'll quit when the user closes the window
  152.             if ( TrackGoAway ( theWindow, theEvent->where ) )
  153.                 gQuit = true;
  154.         break;
  155.         
  156.         case inDrag:
  157.             DoDragWindow ( theWindow, theEvent );
  158.         break;
  159.  
  160.         case inContent:
  161.             DoContentClick ( theWindow, theEvent );
  162.         break;
  163.     }
  164.     
  165.     return;
  166.     
  167. } // DoMouseDown
  168.  
  169.  
  170.  
  171. static void DoKey ( EventRecord* theEvent )
  172. {
  173.     char keyPressed = (theEvent->message & charCodeMask);
  174.     
  175.     
  176.     // Command keys get handled by the menu handling routines
  177.     if ( theEvent->modifiers & cmdKey )
  178.         MenuDispatch ( MenuKey ( keyPressed ) );
  179.     
  180.     return;
  181.     
  182. } // DoKey
  183.  
  184.  
  185.  
  186.  
  187.